package com.kun.lagou.seckillservice.dao;

import com.kun.lagou.seckillservice.model.SeckillOrder;
import org.springframework.data.jpa.repository.Lock;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import javax.persistence.LockModeType;
import java.util.Optional;

/**
 * @author Administrator
 */
@Repository
public interface SeckillOrderDao extends CrudRepository<SeckillOrder, Long> {
    /**
     * 根据用户ID和活动ID查询秒杀订单信息
     * @param userId
     * @param activityId
     * @return
     */
    @Lock(LockModeType.PESSIMISTIC_WRITE)
    Optional<SeckillOrder> findByUserIdAndActivityId(long userId, long activityId);
}
